package com.platform.study.thread;

/**
 * 用实现Runnable接口方式实现线程:线程礼让
 * User: wangyanginfo
 * Date: 12-11-26
 * Time: 下午2:44
 */
public class RunnableSimple_7 implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 500; ++i) {
            System.out.println(Thread.currentThread().getName() + "运行" + i);
            if (i == 100) {
                System.out.println("线程的礼让");
                Thread.currentThread().yield();
            }
        }
    }

    public static void main(String[] args) {
        Thread threadA = new Thread(new RunnableSimple_7(), "线程1");
        Thread threadB = new Thread(new RunnableSimple_7(), "线程2");
        Thread threadC = new Thread(new RunnableSimple_7(), "线程3");
        threadA.start();
        threadB.start();
        threadC.start();
    }
}
